<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>分班人员分页界面</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css"/>
</head>
<body>
<div class="wrap-container clearfix">
    <div class="column-content-detail">
        <form class="layui-form">
            <div class="search-cont clearfix" id="tool">
                <div class="operation-btn-cont">
                    <div class="operright cyt-retract-close hideMenu"> 收起筛选<i class="iconfont">&#xe658;</i></div>
                    <div class="operright cyt-retract-open showMenu" style="display: none;"> 展开筛选<i class="iconfont">&#xe936;</i>
                    </div>
                    <!--button开始-->
                    <button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="addBtn"><i
                            class="iconfont marr5">&#xe65e;</i>添加
                    </button>
                    <button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="deleteBtn"><i
                            class="iconfont marr5">&#xe6a3;</i>删除
                    </button>
                    <button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="resetPasswordBtn"><i
                            class="iconfont marr5">&#xe606;</i>重置密码
                    </button>
                    <button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="import"
                    ><i class="iconfont marr5">&#xe612;</i>导入
                    </button>
                    <!--button结束-->
                    <div class="triangle-bottom"></div>
                    <div class="triangle-top"></div>
                </div>
                <div class="search-details">
                    <div class="layui-form-item marb5">
                        <!--search开始-->
                        <div class="layui-inline">
                            <label class="layui-form-label">工号/学号：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="userNumber" placeholder="请输入工号/学号" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">真实姓名：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" placeholder="请输入真实姓名" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">角色类型：</label>
                            <div class="layui-input-inline">
                                <select name="userType" id="userType">

                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">有效状态：</label>
                            <div class="layui-input-inline w440">
                                <select name="status" id="status" ></select>
                            </div>
                        </div>
                        <!--search结束-->
                        <div class="layui-inline marl8">
                            <button class="layui-btn layui-btn-normal" type="button" lay-submit=""
                                    lay-filter="seacherBtn">搜索
                            </button>
                            <button class="layui-btn layui-btn-normal" type="reset">重置</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <div class="layui-form" id="table-list">
            <table id="entityList" lay-filter="entityList" class="cy-list-table"></table>
        </div>
    </div>
</div>
<!--操作-->
<script type="text/html" id="entityBar">
    <a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-green" lay-event="edit">编辑</a>
    <button type="button" class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-red"
            lay-event="delete">删除
    </button>
</script>
<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    var applyId = '${applyId}';
    var tableIns = null;
    var divideId = '${divideId}';
    layui.use(['jquery', 'form', 'table', 'page', 'dialog', 'baseutil'], function () {
        var $ = layui.jquery,
            page = layui.page,
            table = layui.table,
            form = layui.form,
            baseutil = layui.baseutil,
            dialog = layui.dialog;

        page.initDict('wx_education_user_type,base_status', function (dictData) {
            page.showDict($("#userType"), page.aceeptDictContentList(dictData, 'wx_education_user_type'), "请选择", '${wxEducationUser.userType}');
            page.showDict($("#status"), page.aceeptDictContentList(dictData, 'base_status'), "请选择", '${wxEducationUser.status}');
            var url = "/wx/wxeducationuser/page?applyId=" + applyId + "&examine=" + divideId;
            var cols = [
                {type: 'checkbox', fixed: 'left'},
                {field: 'userNumber', title: '工号/学号', align: 'center'},
                {field: 'name', title: '姓名', align: 'center'},
                {
                    field: 'userType', title: '角色类型', align: 'center', templet: function (d) {
                    return page.aceeptDictContentName(dictData, 'wx_education_user_type', d.userType);
                }
                },
                {field: 'mobile', title: '手机号码', align: 'center'},
                {
                    field: 'status', width: 100, title: '有效状态', align: 'center', templet: function (d) {
                    if (d.status == "1") {
                        return '<input checked="true" data-id="' + d.id + '" name="open" lay-skin="switch" lay-filter="switchStatus" lay-event="editStatus" type="checkbox">';
                    } else {
                        return '<input name="open" data-id="' + d.id + '" lay-skin="switch" lay-filter="switchStatus" lay-event="editStatus" type="checkbox">';
                    }
                }
                },
                {title: '操作', width: 220, templet: '#entityBar', align: "center"}
            ];
            tableIns = page.initDate(cols, url);
        });

        // type类型开启
        form.on('switch(switchStatus)', function (obj) {
            // 获取当前控件
            var id = $(this).attr("data-id");
            var status = "2";
            if (this.checked) {
                status = "1";
            }
            baseutil.AjaxPostMark("/wx/wxeducationuser/updateStatus", {id: id, status: status}, function () {
                tableIns.reload();
            });
        });

        //监听行工具事件
        table.on('tool(entityList)', function (obj) {
            var layEvent = obj.event,
                data = obj.data;
            if (layEvent === 'edit') {
                page.editPopup('/wx/wxeducationuser/getEdit?applyId=' + applyId + '&id=' + data.id, '编辑', "650px", "380px");
            }
            if (layEvent === 'delete') {
                page.delete('/wx/wxeducationuser/remove', {"id": data.id, "_method": "DELETE"}, "确定删除吗？", function () {
                    tableIns.reload();
                });
            }
        });
        $("#import").bind('click', function () {
            divideId=divideId+","+applyId;
            dialog.popUpPage('批量导入用户信息', '/base/import?url=/divideclass/divideclass/importData?divideId=' +divideId+'&download=/upload/WxEducationUserTemplate.xlsx', "500px", "400px", function (layer, index) {
                var body = layer.getChildFrame('body', index);
                body.find("#save").bind("click", function () {
                    parent.layer.closeAll();
                    tableIns.reload();
                });
                body.find("#cancel").bind("click", function () {
                    parent.layer.closeAll();
                });
            });
        });

        //监听添加按钮事件
        $('#addBtn').bind('click', function () {
            page.editPopup('/wx/wxeducationuser/getEdit?applyId=' + applyId, '添加', "650px", "380px");
        });

        //监听删除按钮事件
        $('#deleteBtn').bind('click', function () {
            var data = table.checkStatus('entityList').data;
            if (data.length === 0) {
                dialog.msg("请先选择对象");
                return false;
            } else {
                var ids = [];
                for (var i = 0; i < data.length; i++) {
                    ids.push(data[i].id)
                }
                page.delete('/wx/wxeducationuser/remove', {
                    "id": ids.join(","),
                    "_method": "DELETE"
                }, "您确定要删除吗？", function () {
                    table.reload("entityList", {
                        where: {}
                    });
                });
            }
        });

        //监听重置密码按钮事件，重置为111
        $('#resetPasswordBtn').bind('click', function () {
            var data = table.checkStatus('entityList').data;
            if (data.length === 0) {
                dialog.msg("请先选择对象");
                return false;
            } else {
                var ids = [];
                for (var i = 0; i < data.length; i++) {
                    ids.push(data[i].id)
                }
                page.delete('/wx/wxeducationuser/resetPassword', {"id": ids.join(",")}, "您确定要重置密码吗？", function (res) {
                    // 重置
                    dialog.msg("密码已重置为：" + res);
                    table.reload("entityList", {
                        where: {}
                    });
                });
            }
        });
    });
</script>
</body>
</html>